*** Settings ***
Documentation       通过Redfish修改account组件的LoginInterface的属性值
Library             RequestsLibrary
Library             Collections
Library             String
Suite Setup         Create Redfish Session
Suite Teardown      Delete All Sessions

*** Variables ***
${REDFISH_BASE_URL}         https://127.0.0.1:10443
${ACCOUNT_ID}               2
${SSL_VERIFY}               False
${ETAG}                     ${EMPTY}

*** Test Cases ***
Modify Account Login Interface
    Get User ETag

    ${headers}=    Create Dictionary
    ...    Content-Type=application/json
    ...    X-Auth-Token=${AUTH_TOKEN}
    ...    If-Match=${ETAG}

    # 修改属性内容
    ${login_interface}=    Create List    Redfish    Web
    ${openubmc_dict}=    Create Dictionary    LoginInterface=${login_interface}
    ${oem_dict}=    Create Dictionary    openUBMC=${openubmc_dict}
    ${payload}=    Create Dictionary    Oem=${oem_dict}

    ${rsp}=    PATCH On Session    redfish
    ...    /redfish/v1/AccountService/Accounts/${ACCOUNT_ID}
    ...    json=${payload}
    ...    headers=${headers}

    # 验证响应状态码
    Should Be Equal As Strings    ${rsp.status_code}    200
    ...    msg=修改请求失败, 状态码:${rsp.status_code}

    # 验证返回的LoginInterface值
    ${login_interface}=    Get From Dictionary    ${rsp.json()["Oem"]["openUBMC"]}    LoginInterface
    ${expected_interface}=    Create List    Redfish    Web
    Lists Should Be Equal    ${login_interface}    ${expected_interface}


*** Keywords ***
Create Redfish Session
    # 创建临时会话获取Token
    Create Session    temp_session    ${REDFISH_BASE_URL}
    ...    verify=${SSL_VERIFY}
    ...    disable_warnings=1

    # 获取认证token
    ${auth}=    Create Dictionary
    ...    UserName=Administrator
    ...    Password=Admin@90000

    ${resp}=    POST On Session    temp_session
    ...    /redfish/v1/SessionService/Sessions
    ...    json=${auth}

    ${token}=    Get From Dictionary    ${resp.headers}    X-Auth-Token
    Set Suite Variable    ${AUTH_TOKEN}    ${token}

    # 创建正式会话并携带Token
    ${headers}=    Create Dictionary
    ...    X-Auth-Token=${AUTH_TOKEN}
    ...    Content-Type=application/json

    Create Session    redfish    ${REDFISH_BASE_URL}
    ...    headers=${headers}
    ...    verify=${SSL_VERIFY}
    ...    disable_warnings=1

Get User ETag
    ${headers}=    Create Dictionary
    ...    X-Auth-Token=${AUTH_TOKEN}
    ...    Content-Type=application/json

    ${response}=    GET On Session    redfish
    ...    /redfish/v1/AccountService/Accounts/${ACCOUNT_ID}
    ...    headers=${headers}

    ${etag}=    Get From Dictionary    ${response.headers}    ETag
    ${etag}=    Set Variable If
    ...    $etag is None    "*"
    ...    ${etag}
    Set Suite Variable    ${ETAG}    ${etag}
    Log    ETag值为: ${ETAG}